﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pibby.Core;
using Pibby.Core.Views;

namespace Pibby.UI
{
	public partial class SettingsManagement : Form, IApplicationSettingsView
	{
		public event EventHandler Initialising;
		public event EventHandler InitialiseComplete;

        public IUserSettings Settings { get; set; }

		public SettingsManagement()
		{
			InitializeComponent();
		}

        public SettingsManagement(IUserSettings settings)
			: this ()
		{
			this.Settings = new PerUserSettings(settings);
		}

		private void SettingsManagement_Load(object sender, EventArgs e)
		{
			if (this.Initialising != null)
				this.Initialising(this, EventArgs.Empty);

			if (this.Settings != null)
			{
				this.localStorageFolder.DataBindings.Add("Text", this.Settings, "DownloadFolder");
				this.refreshAtStartupCheckbox.DataBindings.Add("Checked", this.Settings, "RefreshAtStartup");
				this.startupDelayTextBox.DataBindings.Add("Text", this.Settings.Polling, "StartupDelayMinutes");
				this.pollingIntervalTextBox.DataBindings.Add("Text", this.Settings.Polling, "PollingIntervalMinutes");
			}

			if (this.InitialiseComplete != null)
				this.InitialiseComplete(this, EventArgs.Empty);
		}

		void SettingsManagement_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
		{
			var accept = this.AcceptChanges;

			if (accept != null)
				accept(this, EventArgs.Empty);
		}


		public event EventHandler AcceptChanges;

		public event EventHandler DiscardChanges;


		public void Start()
		{
			throw new NotImplementedException();
		}

		public void Stop()
		{
			throw new NotImplementedException();
		}

        private void SettingsManagement_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
            }
        }

		private void button1_Click(object sender, EventArgs e)
		{
			using (SelectMediaDeviceForm form = new SelectMediaDeviceForm())
			{
				form.ShowDialog(this);

				if (form.info != null)
				{

				}

				//form.
			}
		}
	}
}
